package com.luoqy.speedy.modular.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.luoqy.speedy.util.AllException;
import com.luoqy.speedy.util.Result;
import com.luoqy.speedy.util.aop.log.Log;

@Controller
@RequestMapping("/api2")
public class ApiController {
		@RequestMapping("/pay")
		@ResponseBody
		@Log({ "扫码支付", "聚合支付集成" })
		public String sweepCode(HttpServletRequest request) {
		    String userAgent = request.getHeader("user-agent");
		    if (userAgent != null && userAgent.contains("AlipayClient")) {
		    	System.err.println("支付宝");
		        return "来自支付宝";
		    }else if (userAgent != null && userAgent.contains("MicroMessenger")) {
		    	System.err.println("微信");
		        return "来自微信";
		    }else{
		    	System.err.println("其他");
		        return "未知来源";
		    }
		}
		@RequestMapping("/test")
		@ResponseBody
		@Log({ "调用了接口", "api类型" })
		public Result test(String name) {
			try {
				System.err.println(Integer.valueOf(name));
				Result result = new Result();
				result.setMessage("调用成功");
				List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
				Map<String,Object> map=new HashMap<String,Object>();
				map.put("name", "某默默");
				list.add(map);
				return Result.success("成功",list);
			} catch (Exception e) {
				// TODO: handle exception
		        AllException.recordException(e);
				return Result.error("错误");
			}
		}
}
